#pragma once

#include "Model.h"
#include <vector>

namespace algo1 {
	class Token
	{
	public:
		struct Property
		{
			Property(){
				_nodeId = -1;
				_totalCount = 1;
				_myCount = 1;
			};
			int _nodeId;
			int _totalCount;
			int _myCount;		// 1 for single, group is more than 1
		};

		std::vector<Property>	properties;
		Property				group;

		std::vector<Token>		subs;

		bool IsGroup(){
			return group._nodeId != -1;
		};

		bool AddProperty( int nodeId, int totalCount, int myCount = 1 ){
			Property p;
			p._nodeId		= nodeId;
			p._totalCount	= totalCount;
			p._myCount		= myCount;

			properties.push_back( p );

			return true;
		};

		int		uid;
		void GenerateUid(){
			static int nextId = 1000;
			uid = nextId++;
		};


		int		currentNode;

		static Token CreateToken(){
			Token t;
			t.GenerateUid();

			return t;
		};


		int GetCount(){
			if( !IsGroup() ){
				return 1;
			}
			else{
				int count=0;
				for( size_t i=0; i<subs.size(); i++ ){
					count += subs[i].GetCount();
				}
				return count;
			}
		};
	};

	class Event
	{
	public:
		enum TYPE {
			GROUP = 0,
			CREATE
		};

		TYPE _type;	// 0 - group, 1 - create

		int _nodeId;
		std::vector<Token>					_createdTokens;
		std::vector<Token>					_nodeTokens;
		std::map< int, std::vector<Token> >	_outputTokens;
	};

	int RouteCount( CGraphBase& g );

}
